package handler

import (
	"context"
	"fmt"
	"github.com/micro/go-micro"
	user_medreams_com "go-micro-service/interface"
	go_micro_srv_micro_service_api "go-micro-service/proto/user"
)

type UserHandler struct {
	Publisher micro.Publisher
}

func (u *UserHandler) Login(ctx context.Context, in *user_medreams_com.LoginRequest, out *user_medreams_com.LoginResponse) error {
	out.Message = "访问成功"
	out.Data = &user_medreams_com.UserInfo{UserId: 10, UserName: "hello"}
	request := go_micro_srv_micro_service_api.SubmitRequest{
		ProductId: 1,
		Count:     2,
		Uid:       3,
	}
	chanRabbit := make(chan error, 1)
	chanRabbit <- u.Publisher.Publish(ctx, &request)
	go func() {
		for {
			select {
			case err := <-chanRabbit:
				fmt.Println(err)
			}
		}
	}()

	fmt.Println(request)
	return nil
}

func (u *UserHandler) Register(ctx context.Context, in *user_medreams_com.RegisterRequest, out *user_medreams_com.RegisterResponse) error {
	out.Message = "访问成功"
	out.Data = &user_medreams_com.UserInfo{UserId: 10, UserName: "hello"}
	return nil
}

func (u *UserHandler) Verify(ctx context.Context, in *user_medreams_com.VerifyRequest, out *user_medreams_com.VerifyResponse) error {
	out.Message = "访问成功"
	out.Data = "123456789"
	return nil
}
